

/*Data used comes from an excel sheet. The WAPO data in the aggregate 
creates an unbalanced data set. Some states take a few months to get cases
or may not have something reported as of 12/22. These are coded in missing in the 
data instead of zeroes. Not sure why WaPO did this. But I code them as zeroes 
for the synth package since it only uses balanced panel data
*/

import excel "/Users/006489466/Desktop/CA OIS/fillinpanel3.xlsx", sheet("Sheet1") ///
firstrow clear
* assuming missing obs are no OIS 

*note illinois had huge drop in officer data from 2020-2021 (26k to 9k)
* used 26k for 2021 and 2022

*190 obs affected
recode mh . = 0
recode unarmed . = 0
recode ois . = 0

*getting numeric dates

/*want to have comparable data based on rates. pretty rare so will 
go with shootings per million residents. 

will also try per 1,000 officers

and raw count
*/

gen oisp = (ois/pop) * 1000000
la var oisp "FOIS per 1 mill."


gen oiso = (ois/officers) * 1000
la var oiso "FOIS per 1k Officers"



*getting dates situated
gen mdate = mofd(modate)

gen year = yofd(dofm(mdate))
gen month = month(dofm(mdate))

*encode stateid again for panel

encode stateid, gen(sid)

xtset sid mdate, monthly

la var ois "Num. Officer-Involved Shootings"
la var mdate "Time"

*trying out scm 




* really dumb but need the quotes around the time mask thing. took me a long
*time to figure out...


*setting up log. Stata 17.0
log using "/Users/006489466/Desktop/CA OIS/SCMLogResults.log", replace
******************
** RAW COUNT******
******************

synth ois ois(`=tm(2015m1)') ois(`=tm(2015m2)') ois(`=tm(2015m3)') ///
ois(`=tm(2015m4)') ois(`=tm(2015m5)') ois(`=tm(2015m6)') ois(`=tm(2015m7)') ///
ois(`=tm(2015m8)') ois(`=tm(2015m9)') ois(`=tm(2015m10)') ois(`=tm(2015m11)') ///
ois(`=tm(2015m12)') ois(`=tm(2016m1)') ois(`=tm(2016m2)') ois(`=tm(2016m3)') ///
ois(`=tm(2016m4)') ois(`=tm(2016m5)') ois(`=tm(2016m6)') ois(`=tm(2016m7)') ///
ois(`=tm(2016m8)') ois(`=tm(2016m9)') ois(`=tm(2016m10)') ois(`=tm(2016m11)') ///
ois(`=tm(2016m12)') ois(`=tm(2017m1)') ois(`=tm(2017m2)') ois(`=tm(2017m3)') ///
ois(`=tm(2017m4)') ois(`=tm(2017m5)') ois(`=tm(2017m6)') ois(`=tm(2017m7)') ///
ois(`=tm(2017m8)') ois(`=tm(2017m9)') ois(`=tm(2017m10)') ois(`=tm(2017m11)') ///
ois(`=tm(2017m12)') ois(`=tm(2018m1)') ois(`=tm(2018m2)') ois(`=tm(2018m3)') ///
ois(`=tm(2018m4)') ois(`=tm(2018m5)') ois(`=tm(2018m6)') ois(`=tm(2018m7)') ///
ois(`=tm(2018m8)') ois(`=tm(2018m9)') ois(`=tm(2018m10)') ois(`=tm(2018m11)') ///
ois(`=tm(2018m12)') ois(`=tm(2019m1)') ois(`=tm(2019m2)') ois(`=tm(2019m3)') ///
ois(`=tm(2019m4)') ois(`=tm(2019m5)') ois(`=tm(2019m6)') ois(`=tm(2019m7)') ///
ois(`=tm(2019m8)') ois(`=tm(2019m9)') ois(`=tm(2019m10)') ois(`=tm(2019m11)') ///
ois(`=tm(2019m12)'), trunit(5) trperiod(`=tm(2020m1)') figure 

* result indicate Tx and FL are the ones w/ most weight. TX highest prob d/t population

*including just tx and fl control units since all else have zero weights

/*synth ois ois(`=tm(2015m1)') ois(`=tm(2015m2)') ois(`=tm(2015m3)') ///
ois(`=tm(2015m4)') ois(`=tm(2015m5)') ois(`=tm(2015m6)') ois(`=tm(2015m7)') ///
ois(`=tm(2015m8)') ois(`=tm(2015m9)') ois(`=tm(2015m10)') ois(`=tm(2015m11)') ///
ois(`=tm(2015m12)') ois(`=tm(2016m1)') ois(`=tm(2016m2)') ois(`=tm(2016m3)') ///
ois(`=tm(2016m4)') ois(`=tm(2016m5)') ois(`=tm(2016m6)') ois(`=tm(2016m7)') ///
ois(`=tm(2016m8)') ois(`=tm(2016m9)') ois(`=tm(2016m10)') ois(`=tm(2016m11)') ///
ois(`=tm(2016m12)') ois(`=tm(2017m1)') ois(`=tm(2017m2)') ois(`=tm(2017m3)') ///
ois(`=tm(2017m4)') ois(`=tm(2017m5)') ois(`=tm(2017m6)') ois(`=tm(2017m7)') ///
ois(`=tm(2017m8)') ois(`=tm(2017m9)') ois(`=tm(2017m10)') ois(`=tm(2017m11)') ///
ois(`=tm(2017m12)') ois(`=tm(2018m1)') ois(`=tm(2018m2)') ois(`=tm(2018m3)') ///
ois(`=tm(2018m4)') ois(`=tm(2018m5)') ois(`=tm(2018m6)') ois(`=tm(2018m7)') ///
ois(`=tm(2018m8)') ois(`=tm(2018m9)') ois(`=tm(2018m10)') ois(`=tm(2018m11)') ///
ois(`=tm(2018m12)') ois(`=tm(2019m1)') ois(`=tm(2019m2)') ois(`=tm(2019m3)') ///
ois(`=tm(2019m4)') ois(`=tm(2019m5)') ois(`=tm(2019m6)') ois(`=tm(2019m7)') ///
ois(`=tm(2019m8)') ois(`=tm(2019m9)') ois(`=tm(2019m10)') ois(`=tm(2019m11)') ///
ois(`=tm(2019m12)'), trunit(5) trperiod(`=tm(2020m1)') figure counit(10 44)
*/

* data demonstrate no substantive difference in OIS between states post passage


******************
** OIS RATE ******
******************

synth oisp oisp(`=tm(2015m1)') oisp(`=tm(2015m2)') oisp(`=tm(2015m3)') ///
oisp(`=tm(2015m4)') oisp(`=tm(2015m5)') oisp(`=tm(2015m6)') oisp(`=tm(2015m7)') ///
oisp(`=tm(2015m8)') oisp(`=tm(2015m9)') oisp(`=tm(2015m10)') oisp(`=tm(2015m11)') ///
oisp(`=tm(2015m12)') oisp(`=tm(2016m1)') oisp(`=tm(2016m2)') oisp(`=tm(2016m3)') ///
oisp(`=tm(2016m4)') oisp(`=tm(2016m5)') oisp(`=tm(2016m6)') oisp(`=tm(2016m7)') ///
oisp(`=tm(2016m8)') oisp(`=tm(2016m9)') oisp(`=tm(2016m10)') oisp(`=tm(2016m11)') ///
oisp(`=tm(2016m12)') oisp(`=tm(2017m1)') oisp(`=tm(2017m2)') oisp(`=tm(2017m3)') ///
oisp(`=tm(2017m4)') oisp(`=tm(2017m5)') oisp(`=tm(2017m6)') oisp(`=tm(2017m7)') ///
oisp(`=tm(2017m8)') oisp(`=tm(2017m9)') oisp(`=tm(2017m10)') oisp(`=tm(2017m11)') ///
oisp(`=tm(2017m12)') oisp(`=tm(2018m1)') oisp(`=tm(2018m2)') oisp(`=tm(2018m3)') ///
oisp(`=tm(2018m4)') oisp(`=tm(2018m5)') oisp(`=tm(2018m6)') oisp(`=tm(2018m7)') ///
oisp(`=tm(2018m8)') oisp(`=tm(2018m9)') oisp(`=tm(2018m10)') oisp(`=tm(2018m11)') ///
oisp(`=tm(2018m12)') oisp(`=tm(2019m1)') oisp(`=tm(2019m2)') oisp(`=tm(2019m3)') ///
oisp(`=tm(2019m4)') oisp(`=tm(2019m5)') oisp(`=tm(2019m6)') oisp(`=tm(2019m7)') ///
oisp(`=tm(2019m8)') oisp(`=tm(2019m9)') oisp(`=tm(2019m10)') oisp(`=tm(2019m11)') ///
oisp(`=tm(2019m12)'), trunit(5) trperiod(`=tm(2020m1)') figure 

log close

log using "/Users/006489466/Desktop/CA OIS/SCMReviewerResults.log", replace
* Additional analyses for Reviewer 1
* exclude agencies with most weight to assess sensitivity

/* 

So after reviewing donor weights from other places, will only include ones that 
had zero weights in past analysis:

*excluded ones for state population rates so will be used in re-analysis
AR, CO, GA, HA, IA, IL, KY, MD, MN, MO, NC, NB, NH, NJ, NY, OR, PA, RI
SC, SD, TX, UT, VT, WA, WI, WY

*/

*********************
** OIS RATE excluded **
*********************

synth oisp oisp(`=tm(2015m1)') oisp(`=tm(2015m2)') oisp(`=tm(2015m3)') ///
oisp(`=tm(2015m4)') oisp(`=tm(2015m5)') oisp(`=tm(2015m6)') oisp(`=tm(2015m7)') ///
oisp(`=tm(2015m8)') oisp(`=tm(2015m9)') oisp(`=tm(2015m10)') oisp(`=tm(2015m11)') ///
oisp(`=tm(2015m12)') oisp(`=tm(2016m1)') oisp(`=tm(2016m2)') oisp(`=tm(2016m3)') ///
oisp(`=tm(2016m4)') oisp(`=tm(2016m5)') oisp(`=tm(2016m6)') oisp(`=tm(2016m7)') ///
oisp(`=tm(2016m8)') oisp(`=tm(2016m9)') oisp(`=tm(2016m10)') oisp(`=tm(2016m11)') ///
oisp(`=tm(2016m12)') oisp(`=tm(2017m1)') oisp(`=tm(2017m2)') oisp(`=tm(2017m3)') ///
oisp(`=tm(2017m4)') oisp(`=tm(2017m5)') oisp(`=tm(2017m6)') oisp(`=tm(2017m7)') ///
oisp(`=tm(2017m8)') oisp(`=tm(2017m9)') oisp(`=tm(2017m10)') oisp(`=tm(2017m11)') ///
oisp(`=tm(2017m12)') oisp(`=tm(2018m1)') oisp(`=tm(2018m2)') oisp(`=tm(2018m3)') ///
oisp(`=tm(2018m4)') oisp(`=tm(2018m5)') oisp(`=tm(2018m6)') oisp(`=tm(2018m7)') ///
oisp(`=tm(2018m8)') oisp(`=tm(2018m9)') oisp(`=tm(2018m10)') oisp(`=tm(2018m11)') ///
oisp(`=tm(2018m12)') oisp(`=tm(2019m1)') oisp(`=tm(2019m2)') oisp(`=tm(2019m3)') ///
oisp(`=tm(2019m4)') oisp(`=tm(2019m5)') oisp(`=tm(2019m6)') oisp(`=tm(2019m7)') ///
oisp(`=tm(2019m8)') oisp(`=tm(2019m9)') oisp(`=tm(2019m10)') oisp(`=tm(2019m11)') ///
oisp(`=tm(2019m12)'), trunit(5) trperiod(`=tm(2020m1)') counit(3 6 11 12 13 15 ///
18 21 24 25 28 30 31 32 35 38 39 40 41 42 44 45 47 48 49 51) figure 


/*random pool of 25 units set as controls
* drew random sample in R b/c I don't know how to do it in stata

R Code

set.seed(903)
sample(1:51, 25, replace = FALSE)

Output from R to draw random units
13 28 32 20 40 48 26  1 15 30  9 36 29 23 27 12 25  6 14 17 18 11 37 46 10

These will be the control units for the random analysis
*/


*********************
** OIS RATE Random **
*********************
synth oisp oisp(`=tm(2015m1)') oisp(`=tm(2015m2)') oisp(`=tm(2015m3)') ///
oisp(`=tm(2015m4)') oisp(`=tm(2015m5)') oisp(`=tm(2015m6)') oisp(`=tm(2015m7)') ///
oisp(`=tm(2015m8)') oisp(`=tm(2015m9)') oisp(`=tm(2015m10)') oisp(`=tm(2015m11)') ///
oisp(`=tm(2015m12)') oisp(`=tm(2016m1)') oisp(`=tm(2016m2)') oisp(`=tm(2016m3)') ///
oisp(`=tm(2016m4)') oisp(`=tm(2016m5)') oisp(`=tm(2016m6)') oisp(`=tm(2016m7)') ///
oisp(`=tm(2016m8)') oisp(`=tm(2016m9)') oisp(`=tm(2016m10)') oisp(`=tm(2016m11)') ///
oisp(`=tm(2016m12)') oisp(`=tm(2017m1)') oisp(`=tm(2017m2)') oisp(`=tm(2017m3)') ///
oisp(`=tm(2017m4)') oisp(`=tm(2017m5)') oisp(`=tm(2017m6)') oisp(`=tm(2017m7)') ///
oisp(`=tm(2017m8)') oisp(`=tm(2017m9)') oisp(`=tm(2017m10)') oisp(`=tm(2017m11)') ///
oisp(`=tm(2017m12)') oisp(`=tm(2018m1)') oisp(`=tm(2018m2)') oisp(`=tm(2018m3)') ///
oisp(`=tm(2018m4)') oisp(`=tm(2018m5)') oisp(`=tm(2018m6)') oisp(`=tm(2018m7)') ///
oisp(`=tm(2018m8)') oisp(`=tm(2018m9)') oisp(`=tm(2018m10)') oisp(`=tm(2018m11)') ///
oisp(`=tm(2018m12)') oisp(`=tm(2019m1)') oisp(`=tm(2019m2)') oisp(`=tm(2019m3)') ///
oisp(`=tm(2019m4)') oisp(`=tm(2019m5)') oisp(`=tm(2019m6)') oisp(`=tm(2019m7)') ///
oisp(`=tm(2019m8)') oisp(`=tm(2019m9)') oisp(`=tm(2019m10)') oisp(`=tm(2019m11)') ///
oisp(`=tm(2019m12)'), trunit(5) trperiod(`=tm(2020m1)') counit(13 28 32 20 40 48 26 ///
1 15 30 9 36 29 23 27 12 25 6 14 17 18 11 37 46 10) figure 


log close
